package com.zzq.my.jetpacks.jectpackapp.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.google.android.material.imageview.ShapeableImageView
import com.zzq.my.jetpacks.jectpackapp.R
import com.zzq.my.jetpacks.util.loadImage

/**
 * 描述：文本适配器
 * 作者：zhuangzeqin
 * 时间: 2022/1/19-14:16
 * 邮箱：zzq@eeepay.cn
 * 备注:
 */
class ViewPager2BannerAdapter : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_banner) {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
//        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_banner,parent,false);
//        RecyclerView.ViewHolder viewHolder=new RecyclerView.ViewHolder(view);了
//        return viewHolder;
        // todo Pages must fill the whole ViewPager2 (use match_parent)
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_banner, parent, false)
        val layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)
        view.layoutParams = layoutParams
        return BaseViewHolder(view)
    }

    /**
     * Implement this method and use the helper to adapt the view to the given item.
     *
     * 实现此方法，并使用 helper 完成 item 视图的操作
     *
     * @param holder A fully initialized helper.
     * @param item   The item that needs to be displayed.
     */
    override fun convert(holder: BaseViewHolder, item: String) {
        val img = holder.getView<ShapeableImageView>(R.id.banner_image)
        img.loadImage(item)
    }
}